import java.util.Arrays;

public class XuanZheSort {
    public static void main(String[] args) {


        int[] arr = {1, 5, 3, 4};
        //选择排序
        for (int i = 0; i < arr.length - 1; i++) {
            int minIndex = i + 1;
            for (int j = i + 1; j < arr.length - 1; j++) {
                //遍历之后的，进行比较，找到最小值
                if (arr[i] >= arr[j]) {
                    minIndex = j;
                } else {
                    minIndex = i;
                }
            }
            //找到最小值交换
            swap(arr, i, minIndex);
        }
        System.out.println(Arrays.toString(arr));

    }


    public static void swap(int[] arr, int i, int j) {
        int temp = arr[j];
        arr[j] = arr[i];
        arr[i] = temp;
    }
}
